package com.byx.chatserver.mapper;

import org.apache.ibatis.annotations.*;

/**
 * INumberPoolMapper
 *
 * @author Superb
 * @date 2021/4/15 14:46
 */
@Mapper
public interface INumberPoolMapper {
    @Select("select count(number) from number_pool where number_status = 0")
    int queryAvailableNumberPoolSize();

    @Select("select min(number) from number_pool where number_status = 0")
    Long getNextNumber();

    @Update("update number_pool set number_status = 1 where number = #{number}")
    void updateStatus(Long number);

    @Select("select max(number) from number_pool")
    Long getLastNumber();

    @Insert({
            "<script>",
                    "insert into number_pool values ",
                    "<foreach collection = 'numberList' item = 'item' separator = ','>",
                    "(#{item},0)",
                    "</foreach>",
            "</script>"
    })
    void insertNumber(@Param("numberList") Long[] numbers);


    @Delete({
            "<script>" +
                    "delete from number_pool where number in " +
                    "<foreach collection = 'numberList' item = 'item' separator = ',' open = '(' close = ')'>" +
                    "#{item}" +
                    "</foreach>" +
            "</script>"
    })
    void deleteNumber(@Param("numberList") Long[] numbers);
}
